package com.smh.a05PokerGameDemo2;

import java.util.*;

public class PokerGame {

    static HashMap<Integer,String> pokerCord = new HashMap<>();
    static ArrayList<Integer> list = new ArrayList<>();

    static {

        ArrayList<String> color = new ArrayList<>();
        Collections.addAll(color,"♥","♠","♦","♣");
        ArrayList<String> number = new ArrayList<>();
        Collections.addAll(number,"3","4","5","6","7","8","9","10","J","Q","K","A","2");
        int index = 1;
        for (String n : number) {
            for (String c : color) {
                pokerCord.put(index,c+n);
                list.add(index);
                index++;
            }
        }
        pokerCord.put(index,"小王");
        list.add(index);
        index++;
        pokerCord.put(index,"大王");
        list.add(index);
        System.out.println(pokerCord);
    }


    public PokerGame(){
        //打乱
        Collections.shuffle(list);
        //发牌
        //地主()
        TreeMap<Integer,String> lord = new TreeMap();
        TreeMap<Integer,String> player1 = new TreeMap();
        TreeMap<Integer,String> player2 = new TreeMap();
        TreeMap<Integer,String> player3 = new TreeMap();
        for (int i = 0; i < list.size(); i++) {
            if (i<3){
                int index = list.get(i);
                lord.put(index,pokerCord.get(index));
                continue;
            }

            if (i%3==0){
                int index = list.get(i);
                player1.put(index,pokerCord.get(index));
            } else if (i%3==1) {
                int index = list.get(i);
                player2.put(index,pokerCord.get(index));
            }else {
                int index = list.get(i);
                player3.put(index,pokerCord.get(index));
            }
        }

        //看牌
        lookPoker("zhangsan",player1);
        lookPoker("lisi",player2);
        lookPoker("wangwu",player3);

    }

    public void lookPoker(String name,TreeMap<Integer,String> tm){
        System.out.print(name+": ");
        Set<Map.Entry<Integer, String>> entries = tm.entrySet();
        StringJoiner sj =new StringJoiner(",");
        for (Map.Entry<Integer, String> entry : entries) {
            sj.add(entry.getValue());
        }
        System.out.println(sj);
    }
}
